<template>
  <dialog-editor ref="dialog" ></dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'
import {mRequest} from '@/utils/request'

export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      dataFormConfig: {
        id: {
          hidden: true
        },
        messageType: {
          label: '消息类型',
          type: 'radio',
          radioList: [
            {text: '通知公告', label: 4},
            {text: '产品订单', label: 0},
            {text: '模具订单', label: 1},
            {text: '打样订单', label: 2},
            {text: '退货订单', label: 3}
          ],
          default: 4
        },
        roleIdList: {
          label: '通知角色',
          type: 'checkboxGroup',
          checkList: [],
          labelAttr: 'roleId',
          textAttr: 'roleName',
          default: []
        },
        messageInfo:{
          label: '公告内容',
          inputType: 'textarea',
          placeholder: '请输入备注'
        }
      }
    }
  },
  methods: {
    initRoleList() {
      mRequest('systemApi/selectRole', {}, ({data}) => {
        this.dataFormConfig.roleIdList.checkList = this.R.propOr([], 'list', data)
      })
    },
    init(id) {
      this.dataForm.id = id || 0
      this.initUserInfoList('sysUserId')
      this.initRoleList()

      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        dataRule: this.getNeedDataRule('orderDetailId', 'sysUserId', 'hasRead'),
        initApi: 'orderApi/orderMessageInfo',
        saveApi: 'orderApi/saveOrderMessage',
        updateApi: 'orderApi/updateOrderMessage',
        objectName: 'orderMessage'
      })
    }
  }
}
</script>
